#include "type.h"
#include "const.h"
#include "protectmode.h"
#include "process.h"
#include "prototype.h"
#include "string.h"
#include "global.h"

PUBLIC	char			ks1[STACK_SIZE_TOTAL];	//进程1的内核栈
PUBLIC	char			us1[STACK_SIZE_TOTAL];	//进程1的用户栈
PUBLIC	char			ks2[STACK_SIZE_TOTAL];	//进程2的内核栈
PUBLIC	char			us2[STACK_SIZE_TOTAL];	//进程2的用户栈

PUBLIC	char			ks3[STACK_SIZE_TOTAL];	//进程3的内核栈
PUBLIC	char			us3[STACK_SIZE_TOTAL];	//进程3的用户栈


PUBLIC boolean print_story_flag;

PUBLIC boolean thread_test_flag;

//PUBLIC int8* story="OS alpha is a very very simple operating system, developed from scratch by Steven0Lisa with assistance from JackCui.\n\nThanks for the Minix OS, we learnt a lot of thing from it.";

PUBLIC int8* story="\n         (__)          (__)           (__)     ^__^\n         (oo)          (oo)   _______~(..)~    (oo)\\_______\n   /------\\/     /-----(__)     ,----\\(oo)     (__)\\       )\\/\n  / | ||        / | ||         /|____|,'          ||----w |\n * /\\---/\\     * /\\---/\\      * /\"\\ /\\            ||     ||\n    ~~ ~~         ~~ ~~         ~ ~ ~ ~           ~~     ~~\nOS alpha is a very very simple operating system, which is developed from scratch by Steven0Lisa with assistance from JackCui.\n\nThanks for the Minix OS, we learnt a lot of things from its source code.\n\n================================================================================\n";

PRIVATE int story_curr_index=0;

PUBLIC int str_len(int8*);

//初始化系统内核
//整个系统的初始化
PUBLIC void initSystem()
{
		initProcess();
}


void p1()
{
		int i = 0;
		int8 out[2];
		out[0]=out[1]='\0';
		story_curr_index=0;
		print_story_flag=FALSE;
		boolean cls_flag=FALSE;
		while(1)
		{
				//print_str("Process_A:");	//取消这些注释即可看到进程打印的信息
				//disp_int(i++);
				//print_str("  ");

				if(print_story_flag){
						if(!cls_flag){
								cls();
								cls_flag=TRUE;
						}
						if(story[story_curr_index]!='\0'){
								out[0]=story[story_curr_index++];
								print_str(out);
								while(story[story_curr_index]==' '){
										out[0]=story[story_curr_index++];
										print_str(out);
								}
						}else{
								print_story_flag=FALSE;
								cls_flag=FALSE;
						}

				}else{
						story_curr_index=0;
						cls_flag=FALSE;
				}
				delay(1);
		}
}

void p2()
{
		int i = 0;
		thread_test_flag=FALSE;
		while(1)
		{
				//print_str("Process_B:");	//取消这些注释即可看到进程打印的信息
				//disp_int(i++);
				//print_str("  ");
				if(thread_test_flag){
				  print_str("Process A running\n");	//取消这些注释即可看到进程打印的信息
				  i++;
				  //disp_int(i++);
				  //print_str("  ");
				 }else{
				  i=0;
				 }
				delay(60);
				
				if(i>=5)
					break;
		}
		kill_me();
}

void p3()
{
		int i = 0;

		while(1)
		{
				//print_str("Process_C:");	//取消这些注释即可看到进程打印的信息
				//disp_int(i++);
				//print_str("  ");
				if(thread_test_flag){
				  print_str("Process B running\n");	//取消这些注释即可看到进程打印的信息
				  //disp_int(i++);
				  //print_str("\n");
				 }else{
				  i=0;
				 }
				delay(30);
		}
}
